import { defineStore } from 'pinia'
import { store } from '@/store'

/**
 * 键盘状态管理
 *
 */
declare interface keyboardState {
  digitKeyboardConfig: {
    dialogVisible: boolean
    title: string
    modifyItem: any
    balance: number
    type: number
    useBalance: number
  }
  codeKeyboardConfig: {
    dialogVisible: boolean
    title: string
    keyboardValue: string //键盘输入的值
  }
}

export const useShopKeyboard = defineStore('shop-keyboard', {
  state: (): keyboardState => ({
    digitKeyboardConfig: {
      dialogVisible: false, // 是否打开数字键盘
      title: '数字键盘', //数字键盘弹框的标题
      modifyItem: null, // 要求修改的具体内容
      balance: 0, //余额,
      type: 0, //0 修改余额 1修改赠金 2修改支付方式金额 3充值时修改金额 4整单改价
      useBalance: 0 //支付的金额
    },
    codeKeyboardConfig: {
      dialogVisible: false, // 是否打开密码键盘
      title: '请输入密码', //数字键盘弹框的标题
      keyboardValue: '' //输入的值
    }
  }),
  getters: {
    salesPassword(state) {
      return state.codeKeyboardConfig.keyboardValue
    }
  },
  actions: {
    setDigitKeyboardConfig(config: any) {
      this.digitKeyboardConfig = config
    }, //设置数字键盘config
    setDigitKeyboardUseBalanceConfig(useBalance: any) {
      this.digitKeyboardConfig.useBalance = useBalance
    }, //使用的金额
    setCodeKeyboardConfig(config: any) {
      this.codeKeyboardConfig = config
    } //设置支付键盘config
  }
})
export const useShopKeyboardWithOut = () => {
  return useShopKeyboard(store)
}
